<?php

namespace Api\Sms;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration as BaseMigration;

/**
 * 迁移
 */
class Migration extends BaseMigration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /**
         * 短信验证码
         */
        if (! Schema::hasTable('sms__verification_codes')) {
            Schema::create('sms__verification_codes', function (Blueprint $table) {
                $table->engine = 'InnoDB';
                
                $table->string('country_code')                ->comment('国际区号');
                $table->string('mobile')                      ->comment('手机号');
                $table->string('type')                        ->comment('短信类型字符串');
                $table->ipAddress('request_ip')               ->comment('发起请求的 IP 地址');
                $table->string('hash')                        ->comment('哈希校验字符串');
                $table->boolean('hash_fail')->default(false)  ->comment('是否哈希校验错误');
                $table->timestamp('confine_time')->nullable() ->comment('限制时间，超过此时间则该信息无效');

                $table->index('country_code');
                $table->index('mobile');
                $table->index('type');
                $table->index('hash');
            });
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sms__verification_codes');
    }

}
